<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>VUE第一天 v-for</title>
  <style>
    .add-div {
      border: 1px solid #999;
      width: 260px;
    }
    .input {
      width: 50px;
    }
  </style>
</head>
<body>
  <div id="app"> 
    <h2>to do list</h2>
    <input type="text" v-model="thing" @keyup.m="show">
    <button>OK</button>
    <p>待完成事项</p>
    <ul>
      <li v-for="item in todoThings">
        <span>{{item}}</span>
        <button>完成！</button>
      </li>
    </ul>
    <p>已完成事项</p>
    <ul>
      <li v-for="item in doneThings">
        <span>{{item}}</span>
      </li>
    </ul>
    <hr>
    <h2>管理系统</h2>
    <button @click="add">新增</button>
    <table border="1">
      <tr>
        <td>序号</td>
        <td>名称</td>
        <td>电话</td>
        <td>操作</td>
      </tr>
      <tr v-for="item in tableData">
        <td v-for="val in item">{{val}}</td>
        <td><button>删除</button></td>
      </tr>
    </table>
    <div v-show="isAdd" class="add-div">
      <input class="input" type="text" v-model="num">
      <input class="input" type="text" v-model="name">
      <input class="input" type="text" v-model="tel">
      <button>确定</button>
    </div>
  </div>
  <script src="../vue.js"></script>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        thing:'',
        todoThings: ['eat'],
        doneThings: ['sleep'],
        tableData: [
          {num: 1, name: '刘备', tel: '189777'}
        ],
        isAdd: false,
        num: '',
        name: '',
        tel: ''
      },
      methods: {
        add() {
          this.isAdd = true
        },
        show(e) {
          console.log(e.target.value);
        }
      },
    });
  </script>
</body>
</html>